package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;

import com.example.myapplication.fragment.TestDialogShowFragment;
import com.hatom.cameraxhelp.fragment.face.SimpleFaceCameraFragment;
import com.hatom.cameraxhelp.fragment.ocr.OcrCameraFragment;

public class CameraXDemo extends AppCompatActivity {

    private PopupWindow selectPopup;//模式选择popupWindow
    private AppCompatTextView select_mode;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);

        findViewById(R.id.iv_left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        View camerax_selectmodel_windows = getLayoutInflater().inflate(R.layout.camerax_selectmodel_windows, null);
        selectPopup = new PopupWindow(camerax_selectmodel_windows, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        selectPopup.setOutsideTouchable(true);
        select_mode = findViewById(R.id.select_mode);
        select_mode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPopup.showAsDropDown(select_mode);
            }
        });
        camerax_selectmodel_windows.findViewById(R.id.singleocr_mode).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                select_mode.setText("身份证号识别");
                selectPopup.dismiss();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.camerax_fragment, OcrCameraFragment.newInstance())
                        .commitNow();
            }
        });
        camerax_selectmodel_windows.findViewById(R.id.face_mode).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                select_mode.setText("人脸识别");
                selectPopup.dismiss();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.camerax_fragment, SimpleFaceCameraFragment.newInstance())
                        .commitNow();
            }
        });
        camerax_selectmodel_windows.findViewById(R.id.sfz_mode).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                select_mode.setText("身份证识别");
                selectPopup.dismiss();
            }
        });
        camerax_selectmodel_windows.findViewById(R.id.dialog_mode).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                select_mode.setText("人脸弹框");
                selectPopup.dismiss();

                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.camerax_fragment, TestDialogShowFragment.newInstance())
                        .commitNow();
            }
        });
    }

}
